// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ViewViewModel.cs" company="Akzente.IT">
//   (c) 2012 Akzente.IT
// </copyright>
// <summary>
//   The view view model.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AkzenteIT.DatabaseDocumentationTool.ViewModels
{
    using System.Collections.Generic;

    using AkzenteIT.DatabaseDocumentationTool.Extensions;
    using AkzenteIT.DatabaseDocumentationTool.ViewModels.Base;

    using Microsoft.SqlServer.Management.Smo;

    /// <summary>
    /// The view view model.
    /// </summary>
    public class ViewViewModel : DbObjectViewModel<View>
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ViewViewModel"/> class.
        /// </summary>
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <param name="view">
        /// The view.
        /// </param>
        public ViewViewModel(DatabaseViewsViewModel parent, View view)
            : base(parent, view)
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        public override string Description
        {
            get
            {
                return this.Model.ExtendedProperties.GetDescription();
            }

            set
            {
                this.Model.ExtendedProperties.SetDescription(value);
                this.NotifyPropertyChanged("Description");
            }
        }

        /// <summary>
        /// Gets the name.
        /// </summary>
        public override string Name
        {
            get
            {
                return this.Model.Name;
            }
        }

        /// <summary>
        /// Gets the schema.
        /// </summary>
        public string Schema
        {
            get
            {
                return this.Model.Schema;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The to string.
        /// </summary>
        /// <returns>
        /// The System.String.
        /// </returns>
        public override string ToString()
        {
            return (this.Schema == null ? string.Empty : this.Schema + ".") + (this.Name ?? string.Empty);
        }

        #endregion

        #region Methods

        /// <summary>
        /// The load children.
        /// </summary>
        /// <returns>
        /// The System.Collections.Generic.IEnumerable`1[T -&gt; Tools.SqlServerDocGenerator.ViewModels.Base.NodeViewModel].
        /// </returns>
        protected override IEnumerable<NodeViewModel> LoadChildren()
        {
            foreach (Column column in this.Model.Columns)
            {
                yield return new ColumnViewModel(this, column);
            }
        }

        #endregion
    }
}